package route

import (
	_ "frozen-go-mini/docs"
	"frozen-go-mini/route/auth_r"
	"frozen-go-mini/route/banner_r"
	"frozen-go-mini/route/cat_r"
	"frozen-go-mini/route/huichun_r"
	"frozen-go-mini/route/template_r"
	"frozen-go-mini/route/user_r"
	"github.com/gin-gonic/gin"
	ginSwagger "github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
)

func InitRouter() *gin.Engine {
	var r = gin.Default()
	r.Use(Cors()) // 跨域
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	// ws
	//r.GET("/ws", JWTApiHandle, ws_r.WsHandler)
	// http
	noLogin := r.Group("")
	noLogin.Use(ExceptionHandle, LoggerHandle)
	v1 := noLogin.Group("/v1.0", JWTApiHandle)
	{
		v1.GET("/banners", wrapper(banner_r.BannerList))
		v1.GET("/category", wrapper(cat_r.CategoryList))
	}
	auth := v1.Group("auth")
	{
		auth.POST("/code", wrapper(auth_r.AuthByCode))
	}
	user := v1.Group("user")
	{
		user.POST("/update", wrapper(user_r.UpdateUserInfo))
	}

	// 挥春
	huichun := v1.Group("huichun")
	market := huichun.Group("market")
	{
		market.GET("/list", wrapper(huichun_r.MarketList))
		market.GET("/detail/:id", wrapper(huichun_r.MarketDetail))
		market.GET("/specialty", wrapper(huichun_r.MarketSpecialty))
	}
	home := huichun.Group("home")
	{
		home.GET("/notice", wrapper(huichun_r.HomeNotice))
	}
	mine := huichun.Group("mine")
	{
		mine.GET("/footprint", wrapper(huichun_r.MineFootprint))
		mine.POST("collect", wrapper(huichun_r.MineDoCollect))
		mine.GET("collect", wrapper(huichun_r.MyCollect))
	}
	templates := v1.Group("templates")
	{
		templates.GET("/list", wrapper(template_r.TemplateList))
	}
	return r
}
